﻿Imports System.Data.OleDb
Public Class Frm_KhachHang


    Private Sub ComboBox_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        cbxTenPhim.DataSource = bus.GetTable("select * from PHIM")
        cbxTenPhim.DisplayMember = "TenPhim"
        cbxTenPhim.ValueMember = "TenPhim"
    End Sub
    Private _IDKhachHang As String
    Public Property IDKhachHang() As String
        Get
            Return _IDKhachHang
        End Get
        Set(ByVal value As String)
            _IDKhachHang = value
        End Set
    End Property

    Public Sub gvVe_Load()
        ComboBox_Load()
        Dim bus As VeBUS = New VeBUS()
        gvVe.DataSource = bus.GetTable("select * from VE where IDThanhVien = '" & IDKhachHang & "'")
    End Sub
    Public Sub gvSuatChieu_Load()
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        gvSuatChieu.DataSource = bus.GetTable("select * from SUATCHIEU")
    End Sub
    Private Sub Frm_KhachHang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbUserName.Text = Frm_Login.username + " (" + Frm_Login.acctype + ")"
        gvVe_Load()
        gvSuatChieu_Load()
        lbIDThanhVien.Text = IDKhachHang
    End Sub

    Private Sub btnChonGhe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChonGhe.Click
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim dt As DataTable = New DataTable()
        Dim str As String = "select SoDay, SoHang from VE where MaSuatChieu=" + gvSuatChieu.CurrentRow.Cells(0).Value.ToString()
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()

        Dim frm As New frmChonGhe()

        For i = 0 To 9 Step 1
            For j = 0 To 9 Step 1
                Frm_Login.arr(i, j).sl = New Button()
                Frm_Login.arr(i, j).sl.Location = New Point(i * 50, j * 50)
                Frm_Login.arr(i, j).sl.Size = New Size(50, 50)
                Frm_Login.arr(i, j).sl.BackgroundImage = RapChieuPhim.My.Resources.Resources.seat_0
                Frm_Login.arr(i, j).sl.BackgroundImageLayout = ImageLayout.Stretch
                Frm_Login.arr(i, j).sl.Text = (j + 1).ToString() + ":" + (i + 1).ToString()
                AddHandler Frm_Login.arr(i, j).sl.Click, AddressOf frm.Button_Click
                Frm_Login.arr(i, j).st = 0
                frm.Controls.Add(Frm_Login.arr(i, j).sl)
            Next
        Next

        For i = 0 To dt.Rows.Count() - 1 Step 1
            Dim x As Integer = dt.Rows(i)(0) - 1
            Dim y As Integer = dt.Rows(i)(1) - 1
            Frm_Login.arr(x, y).sl.BackgroundImage = RapChieuPhim.My.Resources.Resources.seat_1
            Frm_Login.arr(x, y).sl.Enabled = False
            Frm_Login.arr(x, y).st = 1
        Next

        Frm_Login.banve = New VeDTO()
        Frm_Login.banve.MaSuatChieu = gvSuatChieu.CurrentRow.Cells(0).Value.ToString()
        Frm_Login.banve.GiaVeBan = gvSuatChieu.CurrentRow.Cells(7).Value.ToString()
        Frm_Login.banve.IDThanhVien = Frm_Login.username
        Frm_Login.banve.VeDat = True

        frm.ShowDialog()
        gvVe_Load()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim bus As VeBUS = New VeBUS()
        Dim tmp As VeDTO = New VeDTO()
        tmp.MaVe = lbMaVe.Text
        bus.Delete(tmp)
        MessageBox.Show("Thành công", "Thông báo")
        gvVe_Load()
    End Sub

    Private Sub gvVe_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvVe.SelectionChanged
        Dim bus As VeBUS = New VeBUS()
        Try
            If gvVe.SelectedRows.Count = 0 Then
                Return
            End If
            lbMaVe.Text = gvVe.CurrentRow.Cells(0).Value.ToString()
            lbGiaVe.Text = gvVe.CurrentRow.Cells(2).Value.ToString()

            lbIDThanhVien.Text = IDKhachHang
            lbSoDay.Text = gvVe.CurrentRow.Cells(6).Value.ToString()
            lbSoHang.Text = gvVe.CurrentRow.Cells(5).Value.ToString()

            lbmasuatchieu.Text = gvVe.CurrentRow.Cells(1).Value.ToString()
        Catch
        End Try
    End Sub

    Private Sub cbxTenPhim_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxTenPhim.SelectionChangeCommitted
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Dim str As String = "select * from SUATCHIEU where TenPhim = '%" + cbxTenPhim.Text + "%'"
        gvSuatChieu.DataSource = bus.GetTable(str)
    End Sub

    Private Sub cbxTenPhim_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxTenPhim.SelectedIndexChanged
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Dim str As String = "select * from SUATCHIEU where TenPhim = '" + cbxTenPhim.Text + "'"
        gvSuatChieu.DataSource = bus.GetTable(str)
    End Sub

    Private Sub btnTimSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimSC.Click
        If (rdTimPhongChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaPhongChieu like '%" + txtTimSC.Text + "%'"
            gvSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rdTimPhim.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where TenPhim like '%" + txtTimSC.Text + "%'"
            gvSuatChieu.DataSource = bus.GetTable(str)
        End If
    End Sub

    Private Sub btnSuaMatKhau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaMatKhau.Click
        Dim tv As ThanhVienBUS = New ThanhVienBUS()
        Dim strMatKhauCu As String = "select MatKhau from THANHVIEN where IDThanhVien ='" & IDKhachHang & "'"
        Dim matkhaucu As String = tv.GetValue(strMatKhauCu)

        If (txtMatKhauMoi.Text <> txtNhapLai.Text) Then
            MessageBox.Show("Mật khẩu nhập lại không đúng", "Thông báo")
        ElseIf (txtMatKhauCu.Text <> matkhaucu) Then
            MessageBox.Show("Mật khẩu cũ không đúng", "Thông báo")
        Else
            Dim bus As ThanhVienBUS = New ThanhVienBUS()
            Dim tmp As ThanhVienDTO = New ThanhVienDTO()
            Dim strCMND As String = "select CMND from THANHVIEN where IDThanhVien ='" & IDKhachHang & "'"
            tmp.CMND = bus.GetValue(strCMND)
            tmp.IDThanhVien = IDKhachHang
            tmp.MatKhau = txtMatKhauMoi.Text
            Dim strHSSV As String = "select HSSV from THANHVIEN where IDThanhVien = '" & IDKhachHang & "'"
            tmp.HSSV = Convert.ToBoolean(bus.GetValue(strHSSV))
            Dim strSDT As String = "select SDT from THANHVIEN where IDThanhVien ='" & IDKhachHang & "'"
            tmp.SDT = bus.GetValue(strSDT)
            Dim strten As String = "select TenThanhVien from THANHVIEN where IDThanhVien ='" & IDKhachHang & "'"
            tmp.TenThanhVien = bus.GetValue(strten)
            bus.Update(tmp)
            MessageBox.Show("Ok!!", "Thông báo")
        End If
    End Sub

    Private Sub lbDangXuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDangXuat.Click

        Frm_Login.txtTenDN.Text = ""
        Frm_Login.txtMatKhau.Text = ""
        Frm_Login.txtTenDN.Select()
        Close()
    End Sub

    Private Sub lbUserName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbUserName.Click

    End Sub

    Private Sub help1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles help1.Click
        Help.ShowHelp(Me, Application.StartupPath() + "\HuongDan.chm")
    End Sub
End Class